class AdminController < ApplicationController
  before_filter :login_required
  
  verify :method => :post, :only => [:update, :delete, :create]
  uses_tiny_mce
  
  active_scaffold :job
  
  def index
    @jobs = Job.find(:all, :order => "jid DESC")
    @sectors = Sector.find(:all)
  end
  
  def create
    job = Job.new(params[:job])
    if job.save
      flash[:notice] = "Job was successfully created."
      redirect_to :action => 'index'
    else
      render :action => 'new'
    end
  end
  
  def edit
    @job = Job.find(params[:id])
  end
  
  def update
    job = Job.update(params[:job][:id], params[:job])
    if job.save
      flash[:notice] = "Job was successfully updated."
      redirect_to :action => 'index'
    else
      redirect_to :action => 'edit'
    end
  end
  
  def sectorcreate
    sector = Sector.new(params[:sector])
    if sector.save
      flash[:notice] = 'Sector successfully created.'
      redirect_to :action => 'index'
    else
    end
  end
  
  def sectoredit
    @sector = Sector.find(params[:id])
  end
  
  def sectorupdate
    sector = Sector.update(params[:sector][:id], params[:sector])
    if sector.save
      flash[:notice] = "Sector was successfully updated."
      redirect_to :action => 'index'
    else
      redirect_to :action => 'sectoredit'
    end    
  end
  
  def delete
    if job = Job.delete(params[:id])
      flash[:notice] = "Job was successfully deleted."
      redirect_to :action => 'index'
    end
  end
end